import QtQuick 2.0
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
Rectangle {
    id: root
    property bool isVisible     // 显示动画控制

    height: 0
    color: "#EFF3F8"

    // 显示动画
    state: isVisible ? "show" : "hide"
    states:[
        State{
            name: "show"
            PropertyChanges {
                target: root
                height: 560*dp
            }
        },State{
            name: "hide"
            PropertyChanges {
                target: root
                height: 0
            }
        }
    ]
    transitions: [
        Transition {
            from: "show"
            to: "hide"
            NumberAnimation{
                properties: "height"
                duration: 100
            }
        },Transition {
            from: "hide"
            to: "show"
            NumberAnimation{
                properties: "height"
                duration: 100
            }
        }
    ]

    clip:true

    function update(list){
        dataModel.clear()
        for(let i = 0; i < list.length; i ++){
            dataModel.append({
                                 "item0": list[i][0],
                                 "item1": list[i][1],
                                 "item2": list[i][2],
                                 "item3": list[i][3],
                                 "item4": list[i][4],
                                 "item5": list[i][5],
                                 "item6": list[i][6],
                                 "item7": list[i][7],
                                 "item8": list[i][8],
                                 "item9": list[i][9],
                                 "item10": list[i][10],
                                 "item11": list[i][11],
                             })
        }
    }


    // 表头
    Rectangle{
        height: 60*dp - 1
        width: root.width
        color: "#E6EDF2"
        Row{
            height: parent.height
            width: root.width - 40*dp
            x: 20*dp
            Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "孔位"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "样本名称"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "通道"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "样本类型"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "CT值"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "CT平均值"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "浓度值"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "效率"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "R\xB2"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "截距"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "斜率"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }Item{
                height: parent.height
                width: parent.width / 12
                Text{
                    text: "总浓度值"
                    font.pixelSize: config.fontsize
                    anchors.centerIn: parent
                    font.bold: true
                }
            }
        }
    }
    Item{
        y: 80*dp
        height: 50*dp
        width: root.width
        Text {
            anchors.centerIn: parent
            text: "这里的数据失踪了，换一个实验看看吧"
            font.pixelSize: config.fontsize
            opacity: 0.6
            visible: dataModel.count === 0
        }
    }

    ListView{
        id: repeater
        y: 60*dp
        height: 620*dp
        width: root.width
        clip: model
        model: dataModel
        spacing: 1
        delegate: DetailLine{
            i0:  item0
            i1:  item1
            i2:  item2
            i3:  item3
            i4:  item4
            i5:  item5
            i6:  item6
            i7:  item7
            i8:  item8
            i9:  item9
            i10: item10
            i11: item11
        }
        ScrollBar.vertical: ScrollBar{}
    }
    ListModel{
        id: dataModel
    }

    width: parent.width
    property int idx: 0

}
